package day12.task;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Practice {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String str1 = sc.next();
        String str2 = sc.next();
        Date date = transFormDate(str);
        Date date1 = transFormDate(str1);
        Date date2 = transFormDate(str2);
        boolean flag = str.equals(transString(date));
        System.out.println(flag);
        boolean flag1 = str1.equals(transString(date1));
        boolean flag2 = str2.equals(transString(date2));

        if (!flag) {
            System.out.println(str + "无效！");
        } else {
            Calendar calendar = transFormCalendar(date);
            int i = (calendar.get(Calendar.DAY_OF_WEEK)% 7)+6;
            int a = check(calendar);
            if (a == 1) {
                System.out.println(str + "是闰年.");
                System.out.println(str + "是当年" + calendar.get(Calendar.DAY_OF_YEAR) + "天，当月第" + calendar.get(Calendar.DAY_OF_MONTH) + "天，当周第" + i + "天.");

            } else {
                System.out.println(str + "是当年" + calendar.get(Calendar.DAY_OF_YEAR) + "天，当月第" + calendar.get(Calendar.DAY_OF_MONTH) + "天，当周第" + i + "天.");
            }
        }
        if (flag1 && flag2) {
            Calendar calendar1 = transFormCalendar(date1);
            Calendar calendar2 = transFormCalendar(date2);
            if (calendar1.compareTo(calendar2) > 0) {
                System.out.println(str2 + "早于" + str1 + "，不合法！");
            } else {
                int day = (int) ( calendar2.getTimeInMillis()-calendar1.getTimeInMillis() ) / 86400000;
                int month =  calendar2.get(Calendar.MONTH)-calendar1.get(Calendar.MONTH) ;
                int year = calendar2.get(Calendar.YEAR)-calendar1.get(Calendar.YEAR);
                System.out.println(str2 + "与" + str1 + "之间相差" + day + "天，所在月份相差" + month + ",所在年份相差" + year + ".");
            }
        } else {
            System.out.println(str1 + "或" + str2 + "中有不合法的日期");
        }
    }

    public static String transString(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //创建日期值
        String format = dateFormat.format(date);
        return format;
    }

    public static Date transFormDate(String str) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = dateFormat.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Calendar transFormCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }

    public static int check(Calendar calendar) {
        int a = 0;//返回1为闰年，2为平年
        int year = calendar.get(Calendar.YEAR);
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            a = 1;
        } else {//不是闰年
            a = 2;
        }
        return a;
    }
}
